home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows Expert
/
Windows Expert.iso
/
sound
/
mtlabsnd.zip
/
README.1ST
< prev
next >
Wrap
Text File
|
1993-04-26
|
4KB
|
79 lines
This .ZIP file contains routines to make Matlab/Windows 3.5 and .WAV files
compatible. The routines were written by George Woyansky
(woyansky@flamingo.ece.cmu.edu) and Kevin Bradley (kb35@andrew.cmu.edu) at
Carnegie Mellon University for use in a course here and we figured that
they'd be useful to the rest of the world (at least that portion of the
world waiting for Windows 4.0 and its promised sound capabilities).
SOUND FILE IMPORT/EXPORT
========================
First, to get .WAV files in and out of Matlab, we wrote an extension for the
SOX (SOund eXchange) program to allow SOX to read/write .MAT files directly.
The files needed to allow Matlab to read/write .WAV files are:
readwav.m <-- wrapper around SOX.EXE to read in .WAV file
writewav.m <-- wrapper around SOX.EXE to write .WAV file from a vector
sox.exe <-- requires windows; source provided if you want to recompile
for DOS (use Borland C++ project file SOX.PRJ)
Basically, you can use readwav.m to read any .WAV file into a Matlab vector,
and writewav.m to write out ANY matlab vector as a mono .WAV file.
writewav.m requires that you also specify a sampling rate (in Hz) and a data
size - either 8 or 16 bits/sample. We don't check to ensure that your data
fits within the data size you specify, so make sure before you write your
data to a .WAV file that it's within the range supported by 8 or 16 bits.
Writewav also assumes that the Matlab data is signed - that is, -128 to +127
for 8-bit data and -32768 to +32767 for 16-bit data. Data points having
nonzero fractional component are rounded to the nearest int.
Caveat/cop-out: we only support mono audio read/writes; if you try to read
in a stereo .wav file what you'll get is a vector with the left and right
channel data interleaved, i.e. [left(1);right(1);left(2);right(2)...]
SOUND PLAYBACK
==============
Next, Windows has some fancy playback tools but most require mouse
interaction. We wanted one that would work from the Matlab command line -
i.e. play('soundfile') from the >> prompt. Two files implement this
feature:
play.m <-- wrapper around PLAYW.EXE
playw.exe <-- Windows executable that plays .WAV file specified as its
only argument.
PLAYW.EXE uses the Borland C++ Windows extensions and essentially plays the
.WAV file specified as argv[1]. It does no checking to make sure that the
file is a valid .WAV file, and you must supply the .WAV extension. You may
supply a path as well when you specify the file.
Using these routines: a sample scenario
=======================================
Assume that you've got a file called SOUND.WAV. The commands you could use
from within Matlab (>> omitted for clarity) to manipulate the data in that
file are:
soundvect = readwav('SOUND'); % reads from SOUND.WAV into soundvect
linramp = (1:length(soundvect))/length(soundvect); % Generate a linear ramp
newsound = soundvect.*linramp; % A fade-in effect
writewav('NEWSOUND',newsound,8000,16); % Write the file at 8kHz, 16 bits/sa
play('NEWSOUND');
etc. etc. etc.
We hope that you enjoy using these tools. No guarantee is made as to the
functionality or correctness of the code. These tools are released to the
public domain. Any use of these tools for commercial gain is prohibited.
The Free Software Foundation's CopyLeft Policy applies.
George Woyansky
Kevin Bradley
Carnegie Mellon University
Department of Electrical and Computer Engineering
5000 Forbes Avenue
Pittsburgh, PA 15213
April, 1993